package com.lh.blogResource.service.impl;

import com.lh.blogCommon.util.PageUtils;
import com.lh.blogCommon.util.Query;
import com.lh.blogResource.entity.ResourceTypeEntity;
import com.lh.blogResource.entity.ResourcesEntity;
import com.lh.blogResource.mapper.ResourceTypeMapper;
import com.lh.blogResource.service.ResourceTypeService;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;


@Service("resourceTypeService")
public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, ResourceTypeEntity> implements ResourceTypeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<ResourceTypeEntity> queryWrapper = new QueryWrapper<>();

        String key = (String) params.get("key");

        if(!StringUtils.isEmpty(key)){
            queryWrapper.eq("resourcetype_id",key).or()
                    .eq("resourcetype_name",key);
        }
        queryWrapper.orderByDesc("resourcetype_id");

        IPage<ResourceTypeEntity> page = this.page(
                new Query<ResourceTypeEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}